package com.ittao.taopicturebackend.api.imagesearch;

import com.ittao.taopicturebackend.api.imagesearch.model.ImageSearchResult;
import com.ittao.taopicturebackend.api.imagesearch.sub.GetImageFirstUrlApi;
import com.ittao.taopicturebackend.api.imagesearch.sub.GetImageListApi;
import com.ittao.taopicturebackend.api.imagesearch.sub.GetImagePageUrlApi;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 实现以图搜图功能Api
 * 门面模式（高内聚，低耦合）
 */
@Slf4j
public class ImageSearchApiFacade {

    public static List<ImageSearchResult> searchImage(String searchText) {
        String imagePageUrl = GetImagePageUrlApi.getImagePageUrl(searchText);
        String imageFirstUrl = GetImageFirstUrlApi.getImageFirstUrl(imagePageUrl);
        List<ImageSearchResult> imageList = GetImageListApi.getImageList(imageFirstUrl);
        return imageList;
    }

    public static void main(String[] args) {
        List<ImageSearchResult> imageSearchResults = searchImage("https://tse1-mm.cn.bing.net/th/id/OIP-C.XS6EtBzAmWWa31cfFvcx6QHaHa?w=163&h=180&c=7&r=0&o=7&dpr=1.3&pid=1.7&rm=3");
        System.out.println("图片列表：" + imageSearchResults);
    }
}
